package cn.wolfcode.trip.app.controller;

import cn.wolfcode.trip.base.domain.StrategyDoubleComment;
import cn.wolfcode.trip.base.service.IStrategyDoubleCommentService;
import cn.wolfcode.trip.base.service.ITagService;
import cn.wolfcode.trip.base.util.JsonResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Controller
@RequestMapping("/strategydoublecomment")
public class StrategyDoubleCommentController {

    @Autowired
    private IStrategyDoubleCommentService strategyDoubleCommentService;
    @Autowired
    private ITagService             tagService;

    //根据评论ID找所有对应子评论
    @GetMapping("/{strategycommentId}")
    @ResponseBody
    public Object  getBystrategycommentId(@PathVariable("strategycommentId") Long strategycommentId){
        List<StrategyDoubleComment> list = strategyDoubleCommentService.selectBystrategycommentId(strategycommentId);
        return list;
    }
    //根据评论ID找所有对应子评论
    @GetMapping("/{strategycommentId}/count")
    @ResponseBody
    public Object  getCountNumBystrategycommentId(@PathVariable("strategycommentId") Long strategycommentId){
        int num = strategyDoubleCommentService.selectCountNumBystrategycommentId(strategycommentId);
        return num;
    }
    //子评论新增接口
    @PostMapping
    @ResponseBody
    public JsonResult create(StrategyDoubleComment strategyDoubleComment){
        JsonResult jsonResult = new JsonResult();
        try {
            strategyDoubleCommentService.saveOrUpdate(strategyDoubleComment);
            return jsonResult;
        } catch (Exception e) {
            e.printStackTrace();
            jsonResult.mark("服务器繁忙");
            return jsonResult;
        }
    }

}
